package domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class Sale {
    private List<SalesLineItem> lineItems = new ArrayList<>();
    private Date date = new Date();
    private boolean isComplete = false;
    private Payment payment;

    public Money getBalance() {
        if (payment == null)
            return new Money(0.0);
        return payment.getAmount().minus(getTotal());
    }

    public void becomeComplete() {
        isComplete = true;
    }

    public boolean isComplete() {
        return isComplete;
    }

    public void makeLineItem(ProductDescription desc, int quantity) {
        lineItems.add(new SalesLineItem(desc, quantity));
    }

    public Money getTotal() {
        Money total = new Money(0.0);
        for (SalesLineItem lineItem : lineItems) {
            total = total.add(lineItem.getSubtotal());
        }
        return total;
    }

    public void makePayment(Money cashTendered) {
        payment = new Payment(cashTendered);
    }

    public Object getStatus() {
        // TODO Auto-generated method stub
        throw new UnsupportedOperationException("Unimplemented method 'getStatus'");
    }
    public List<SalesLineItem> getLineItems() {
        return lineItems;
    }
}
